﻿//---------------------------------------------------------------------------------------------------------
//	Copyright © 2007 - 2018 Tangible Software Solutions Inc.
//	This class can be used by anyone provided that the copyright notice remains intact.
//
//	This class is used to replace calls to Java's System.currentTimeMillis with the C# equivalent.
//	Unix time is defined as the number of seconds that have elapsed since midnight UTC, 1 January 1970.
//---------------------------------------------------------------------------------------------------------
public static class DateTimeHelper
{
    private static readonly System.DateTime Jan1st1970 = new System.DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc);
    public static long CurrentUnixTimeMillis()
    {
        return (long)(System.DateTime.UtcNow - Jan1st1970).TotalMilliseconds;
    }

    public static System.DateTime StringToDateTime(string createTime)
    {
        double timeVal;
        if (!string.IsNullOrEmpty(createTime))
        {
            timeVal = double.Parse(createTime);

            return System.DateTime.Parse(System.DateTime.Now.ToString("1970-01-01 00:00:00")).AddMilliseconds(timeVal); ;
        }
        return System.DateTime.Now;
    }
}